package com.szr.leex.po.base;

import java.time.LocalDateTime;
import java.util.Date;

import javax.persistence.EntityListeners;
import javax.persistence.MappedSuperclass;
import javax.persistence.Temporal;

import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import lombok.Data;

import static javax.persistence.TemporalType.TIMESTAMP;

/**
 * 审计信息
 * Spring Data JPA Auditing: Saving CreatedBy, CreatedDate, LastModifiedBy, LastModifiedDate automatically
 * 参考 :
 * https://programmingmitra.blogspot.com/2017/02/automatic-spring-data-jpa-auditing-saving-CreatedBy-createddate-lastmodifiedby-lastmodifieddate-automatically.html
 * https://github.com/njnareshjoshi/articles/tree/master/spring-data-jpa-auditing
 * Created by WangChen on 2018/9/10 13:55.
 */
@Data
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class Auditing<U> extends StatusEntity {

    @CreatedBy
    protected U createdBy;

    @CreatedDate
    //@Temporal should only be set on a java.util.Date or java.util.Calendar property
//    @Temporal(TIMESTAMP)
    protected LocalDateTime createdDateTime;

    @LastModifiedBy
    protected U lastModifiedBy;

    @LastModifiedDate
    @Temporal(TIMESTAMP)
    protected Date lastModifiedDate;

}
